package com.legal.app.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.legal.app.domain.vo.LawyerCommentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.legal.common.annotation.Log;
import com.legal.common.core.controller.BaseController;
import com.legal.common.core.domain.AjaxResult;
import com.legal.common.enums.BusinessType;
import com.legal.app.domain.LawyerComment;
import com.legal.app.service.ILawyerCommentService;
import com.legal.common.utils.poi.ExcelUtil;
import com.legal.common.core.page.TableDataInfo;

/**
 * 律师评论Controller
 * 
 * @author Ale
 * @date 2025-05-30
 */
@RestController
@Api(tags = "律师评论模块")
@RequestMapping("/app/comment")
public class LawyerCommentController extends BaseController
{
    @Autowired
    private ILawyerCommentService lawyerCommentService;

    /**
     * 查询律师评论列表
     */
    @PreAuthorize("@ss.hasPermi('app:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(LawyerComment lawyerComment)
    {
        startPage();
        List<LawyerComment> list = lawyerCommentService.selectLawyerCommentList(lawyerComment);
        return getDataTable(list);
    }

    /**
     * 导出律师评论列表
     */
    @PreAuthorize("@ss.hasPermi('app:comment:export')")
    @Log(title = "律师评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LawyerComment lawyerComment)
    {
        List<LawyerComment> list = lawyerCommentService.selectLawyerCommentList(lawyerComment);
        ExcelUtil<LawyerComment> util = new ExcelUtil<LawyerComment>(LawyerComment.class);
        util.exportExcel(response, list, "律师评论数据");
    }

    /**
     * 获取律师评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:comment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(lawyerCommentService.selectLawyerCommentById(id));
    }

    /**
     * 新增律师评论
     */
    @PreAuthorize("@ss.hasPermi('app:comment:add')")
    @Log(title = "律师评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LawyerComment lawyerComment)
    {
        return toAjax(lawyerCommentService.insertLawyerComment(lawyerComment));
    }

    /**
     * 修改律师评论
     */
    @PreAuthorize("@ss.hasPermi('app:comment:edit')")
    @Log(title = "律师评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LawyerComment lawyerComment)
    {
        return toAjax(lawyerCommentService.updateLawyerComment(lawyerComment));
    }

    /**
     * 删除律师评论
     */
    @PreAuthorize("@ss.hasPermi('app:comment:remove')")
    @Log(title = "律师评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(lawyerCommentService.deleteLawyerCommentByIds(ids));
    }


    /**
     * 律师回复评论
     */
    @PostMapping("/reply")
    @Log(title = "律师评论", businessType = BusinessType.UPDATE)
    @ApiOperation("律师回复评论")
    public AjaxResult reply(@RequestParam("id") Long id,
                                             @RequestParam String content) {
        return lawyerCommentService.replyComment(id, content);
    }

    /**
     * 新增律师评论
     */
    @PreAuthorize("@ss.hasPermi('app:comment:add')")
    @Log(title = "律师评论", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult addCommentByOrder(@RequestBody Map<String, Object> params) {
        // 1. 解析参数
        Long orderId = Long.valueOf(params.get("orderId").toString());
        String content = (String) params.get("content");
        //Integer rating = params.get("rating") != null ? Integer.valueOf(params.get("rating").toString()) : 5;

        // 2. 调用服务发表评论
        AjaxResult result = AjaxResult.success(lawyerCommentService.addCommentByOrder(orderId, content));
        return result;
    }


    @PreAuthorize("@ss.hasPermi('app:comment:list')")
    @GetMapping("/lists")
    @Log(title = "律师评论", businessType = BusinessType.OTHER)
    public TableDataInfo lists(LawyerComment lawyerComment) {
        startPage();
        List<LawyerCommentVO> list = lawyerCommentService.selectLawyerCommentVOList(lawyerComment);
        return getDataTable(list);
    }


}
